package test.src.awt_swing;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ProgressMonitorDemo {
    Timer timer;
    public void init() {
        final SimulatedActivity simulatedActivity = new SimulatedActivity(100);
        final Thread targetThread = new Thread(simulatedActivity);
        targetThread.start();

        ProgressMonitor dialog = new ProgressMonitor(null, "等待任务完成", "已完成", 0,
                simulatedActivity.getAmount());

        timer = new Timer(300, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.setProgress(simulatedActivity.getCurrent());
                if (dialog.isCanceled()) {
                    timer.stop();
                    targetThread.interrupt();
                    System.exit(0);
                }
            }
        });

        timer.start();

        System.out.println("aaa");
    }

    public static void main(String[] args) {
        new ProgressMonitorDemo().init();
    }
}
